﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BestLifePOS_Core.Data.Core;
using System.Data;
using System.Data.SqlClient;
using BestLifePOS_Core.Exceptions.DataBase;

namespace BestLifePOS_Core.Data.Commands
{
    class BestLifeGetAllProductByProductIDDataAction : BestLifeDataAction<DataTable>
    {
       
            private string Gvproductid;
            private string Gvcatid;
            DataTable GvTable = new DataTable();
            public BestLifeGetAllProductByProductIDDataAction(string Pproductid)
            {
                Gvproductid = Pproductid;
               
            }


            public override DataTable Body(SqlConnection PConn)
            {
                try
                {

                    #region Datatable

                    GvTable.Columns.Add("Pro_ID");
                    GvTable.Columns.Add("Cat_Name");
                    GvTable.Columns.Add("Sub_Cat_Name");
                    GvTable.Columns.Add("Brand_Name");
                    GvTable.Columns.Add("Unit");
                    GvTable.Columns.Add("Unit_Description");
                    GvTable.Columns.Add("Description");
                    GvTable.Columns.Add("Pro_Name");
                    GvTable.Columns.Add("Status");
                    GvTable.Columns.Add("Date_Create");
                    GvTable.Columns.Add("User_Modify");
                    GvTable.Columns.Add("Last_Modify");
                    GvTable.Columns.Add("Barcode");
                    #endregion

                    List<string> LvList = new List<string>();


                    SqlCommand LvCommand = new SqlCommand();
                    LvCommand.Connection = PConn;
                    LvCommand.CommandType = CommandType.StoredProcedure;
                    LvCommand.CommandText = "dbo.GetProductDetailsByProID";
                    LvCommand.Parameters.Add(new SqlParameter("@ProductID", Gvproductid));//when passing parameters to the SP
                    //LvCommand.Parameters.Add(new SqlParameter("@CatID", Gvproductid));//Pass Second Parameter

                   


                    SqlDataReader LvReader = LvCommand.ExecuteReader();
                    while (LvReader.Read())
                    {


                        GvTable.Rows.Add(GvTable.NewRow());

                        GvTable.Rows[GvTable.Rows.Count - 1][0] = LvReader.GetValue(0).ToString();
                        GvTable.Rows[GvTable.Rows.Count - 1][1] = LvReader.GetValue(1).ToString();
                        GvTable.Rows[GvTable.Rows.Count - 1][2] = LvReader.GetValue(2).ToString();
                        GvTable.Rows[GvTable.Rows.Count - 1][3] = LvReader.GetValue(3).ToString();
                        GvTable.Rows[GvTable.Rows.Count - 1][4] = LvReader.GetValue(4).ToString();
                        GvTable.Rows[GvTable.Rows.Count - 1][5] = LvReader.GetValue(5).ToString();
                        GvTable.Rows[GvTable.Rows.Count - 1][6] = LvReader.GetValue(6).ToString();
                         GvTable.Rows[GvTable.Rows.Count - 1][7] = LvReader.GetValue(7).ToString();
                         GvTable.Rows[GvTable.Rows.Count - 1][8] = LvReader.GetValue(8).ToString();
                         GvTable.Rows[GvTable.Rows.Count - 1][9] = LvReader.GetValue(9).ToString();
                         GvTable.Rows[GvTable.Rows.Count - 1][10] = LvReader.GetValue(10).ToString();
                         GvTable.Rows[GvTable.Rows.Count - 1][11] = LvReader.GetValue(11).ToString();
                         GvTable.Rows[GvTable.Rows.Count - 1][12] = LvReader.GetValue(12).ToString();
                        



                    }
                    return GvTable;
                }
                catch (BestlifeDatabaseException e)
                {
                    throw new BestlifeDatabaseException(e);
                }
            }

        }
    }

